package com.mbc.controller;


import com.mbc.comment.Result;
import com.mbc.dto.MbcAnimalShelterDTO;
import com.mbc.dto.MbcRealNameAuthenticationDTO;
import com.mbc.dto.GetMbcAnimalShelterDTO;
import com.mbc.service.AnimalShelterService;
import com.mbc.vo.GetMbcAnimalShelterVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * <p>
 * 流浪动物庇护所表 前端控制器
 * </p>
 *
 * @author suimeng
 * @since 2024-04-17
 */
@RestController
@RequestMapping("/animalShelter")
@Api(tags = "庇护所接口")
@CrossOrigin
public class AnimalShelterController {

    @Autowired
    private AnimalShelterService animalShelterService;

    /**
     * 新增动物庇护所
     *
     * @param userId              用户 ID
     * @param mbcAnimalShelterDTO MBC 动物收容所 DTO
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/insert/{userId}")
    @ApiOperation("新增动物庇护所")
    public Result<Boolean> insertAnimalShelter(@PathVariable Integer userId,
                                               @RequestBody MbcAnimalShelterDTO mbcAnimalShelterDTO) {
        return Result.success(animalShelterService.insertAnimalShelter(userId, mbcAnimalShelterDTO));
    }

    /**
     * 新增动物庇护所创建人的实名认证
     *
     * @param userId                       用户 ID
     * @param mbcRealNameAuthenticationDTO MBC实名认证DTO
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/insert/realName/{userId}")
    @ApiOperation("新增动物庇护所创建人的实名认证")
    public Result<Boolean> insertRealNameAuthentication(@PathVariable Integer userId,
                                                        @RequestBody MbcRealNameAuthenticationDTO mbcRealNameAuthenticationDTO) {
        return Result.success(animalShelterService.insertRealNameAuthentication(userId,mbcRealNameAuthenticationDTO));
    }

    /**
     * 全查和条件查询庇护所
     *
     * @param getMbcAnimalShelterDTO 获取 MBC 动物收容所 DTO
     * @return {@link Result}<{@link ArrayList}<{@link GetMbcAnimalShelterVO}>>
     */
    @GetMapping("/get")
    @ApiOperation("分页全查和条件查询庇护所")
    public Result<ArrayList<GetMbcAnimalShelterVO>> getByAnimalShelter(GetMbcAnimalShelterDTO getMbcAnimalShelterDTO) {
        ArrayList<GetMbcAnimalShelterVO> list = animalShelterService.getByAnimalShelter(getMbcAnimalShelterDTO);
        return Result.success(list);
    }

    /**
     * 根据id查询庇护所详细信息
     *
     * @param shelterId 避难所 ID
     * @return {@link Result}<{@link GetMbcAnimalShelterVO}>
     */
    @GetMapping("/get/{shelterId}")
    @ApiOperation("根据id查询庇护所详细信息")
    public Result<GetMbcAnimalShelterVO> getByIdAnimalShelter(@PathVariable Integer shelterId) {
        GetMbcAnimalShelterVO getMbcAnimalShelterVO = animalShelterService.getByIdAnimalShelter(shelterId);
        return Result.success(getMbcAnimalShelterVO);
    }

    /**
     * 更新动物收容所
     *
     * @param mbcAnimalShelterDTO MBC 动物收容所 DTO
     * @param userId              用户 ID
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/update/{userId}")
    @ApiOperation("更新动物庇护所信息")
    public Result<Boolean> updateAnimalShelter(@RequestBody MbcAnimalShelterDTO mbcAnimalShelterDTO,
                                               @PathVariable Integer userId) {
        return Result.success(animalShelterService.updateAnimalShelter(mbcAnimalShelterDTO, userId));
    }

    /**
     * 删除动物收容所
     *
     * @param userId 用户 ID
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/delete/{userId}")
    @ApiOperation("删除宠物收纳所")
    public Result<Boolean> deleteAnimalShelter(@PathVariable Integer userId) {
        return Result.success(animalShelterService.deleteAnimalShelter(userId));
    }
}
